package com.apes.fn.server.reworkAppraisal.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.*;
import com.apes.scm.masterdata.stock.model.Location;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 功能：返修鉴定单明细
 *
 * @author wsj
 * @create 2019-12-31 11:23
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ReworkAppraisalItem.CONST_TABLE_NAME)
public class ReworkAppraisalItem extends BaseModel {
    public static final String CONST_TABLE_NAME = "crm_rework_appraisal_item";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "返修鉴定单明细")
    @Comment("明细单号")
    private Long id;   //单号


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="rework_appraisal_id", referencedColumnName="id", nullable = false)
    @Comment("返修鉴定单号")
    private ReworkAppraisal reworkAppraisal;

    // TODO 后期补上商品相关信息
    // @ManyToOne(fetch = FetchType.LAZY)
    // @JoinColumn(name = "classify_id", referencedColumnName = "id", nullable = false)
    // @Comment("商品分类")
    // private Classify classify;
    //
    // @NotNull
    // @ManyToOne(fetch = FetchType.LAZY)
    // @JoinColumn(name = "location_id", referencedColumnName = "id")
    // @Comment("仓库库区")
    // private Location location;
    //
    // @ManyToOne(fetch = FetchType.LAZY)
    // @JoinColumn(name = "supplier_id", referencedColumnName = "id")
    // @Comment("供应商")
    // private PartyRole supplier;
    //
    // @ManyToOne(fetch = FetchType.LAZY)
    // @JoinColumn(name = "brand_id", referencedColumnName = "id")
    // @Comment("品牌")
    // private Brand brand;
    //
    // @ManyToOne(fetch = FetchType.LAZY)
    // @JoinColumn(name = "product_uom_id", referencedColumnName = "id", nullable = false)
    // @Comment("计量单位")
    // private ProductUom uom;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id", nullable = false)
    @Comment("商品")
    private Product product;

    // @ManyToOne(fetch = FetchType.LAZY)
    // @JoinColumn(name = "product_group_id", referencedColumnName = "id", nullable = false)
    // @Comment("商品组")
    // private ProductGroup productGroup;


    @Comment("责任方")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "responsible_party", referencedColumnName = "id")
    private Enumeration responsibleParty;

    @Comment("返修原因")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "rework_reason", referencedColumnName = "id")
    private Enumeration reworkReason;

    @Comment("施工方")
    @Column(name = "construction_side", length = 300)
    private  String constructionSide;

    @Column(name = "price_total", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("总计")
    private double priceTotal = 0;

    @Column(name = "unit_price", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("单价")
    private double unitPrice = 0;

    @Column(name = "discount_price", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("优惠单价")
    private double discountPrice = 0;

    @Column(name = "red_packet", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("红包金额")
    private double redPacket = 0;

    @Column(name = "product_qty", nullable = false)
    @Comment("数量")
    private double productQty = 0;

    // @ManyToOne(fetch = FetchType.LAZY)
    // @JoinColumn(name = "tax_id", referencedColumnName = "id", nullable = false)
    // @Comment("税率")
    // private Tax tax;

    @Column(name = "warranty_qty", nullable = false)
    @Comment("质保数量")
    private double warrantyQty = 0;

    @Column(name = "warranty_period")
    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Comment("质保期止")
    private Date warrantyPeriod;

    @Column(name = "warranty_amount", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("质保金额")
    private double warrantyAmount;

    @States(name = "质保状态", values = {
            @State(id = "A", name = "为质保"),
            @State(id = "B", name = "已质保")})
    @Column(name = "warranty_status", length = 10)
    @Comment("质保状态")
    private String warrantyStatus;

    @Column(name = "warranty_mileage", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("质保里程止")
    private double warrantyMileage;


    @Column(name = "buckle_last_bonus",nullable = false,columnDefinition = ApesConst.FIELD_BOOLEAN_FALSE)
    @Comment("扣上次提成标记")
    private boolean buckleLastBonus = false;

    @Column(name = "buckle_this_bonus",nullable = false,columnDefinition = ApesConst.FIELD_BOOLEAN_FALSE)
    @Comment("扣本次提成标记")
    private boolean buckleThisBonus = false;

}
